package com.heima.crm.controller;


import com.heima.crm.common.result.PageResult;
import com.heima.crm.common.result.Result;
import com.heima.crm.pojos.dtos.*;
import com.heima.crm.pojos.vos.BusinessPageVo;
import com.heima.crm.service.TbBusinessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-07-15
 */
@RestController
@RequestMapping("/business")
@Slf4j
public class TbBusinessController {

    @Autowired
    private TbBusinessService tbBusinessService;

    @GetMapping("/list")
    public Result<PageResult<BusinessPageVo>> findAllBusiness(BusinessPageDto dto){




        log.info("商机分页查询");

        return tbBusinessService.findAllBusiness(dto);
    }

    @PostMapping("/save")
    public Result addBusiness(@RequestBody BusinessAddDto dto){
        log.info("新增商机");

        return tbBusinessService.addBusiness(dto);
    }

    /**
     * 查看用户所有跟进记录
     * @return
     */
    @GetMapping("/follow/{businessId}")
    public Result findCustomerCondition(@PathVariable Long businessId){
        log.info("查看客户id为{}的所有跟进记录",businessId);

        return tbBusinessService.findCustomerCondition(businessId);
    }

    /**
     * 分配商机
     * @param dto
     * @return
     */
    @PostMapping("/assign")
    public Result assignBusiness( BusinessAssignDto dto){

        return tbBusinessService.assignBusiness(dto);
    }

    /**
     *商机数据详情回显
     * @param businessId
     * @return
     */
    @GetMapping("/businessDetail/{businessId}")
    public Result findBusinessDetail(@PathVariable Long businessId){
        log.info(businessId+"商机数据回显");

        return tbBusinessService.findBusinessDetail(businessId);
    }

    @PostMapping("/follow")
    public Result followBusiness(@RequestBody BusinessFollowDto dto){
        log.info("添加沟通记录或修改用户基本信息");

        return tbBusinessService.followBusiness(dto);
    }

    @PutMapping("/returnBusiness")
    public Result returnBusiness(@RequestBody BusinessReturnDto dto){
        log.info("退回公海");

        return tbBusinessService.returnBusiness(dto);
    }

    @PutMapping("/scoopBatch")
    public Result scoopBatch(@RequestParam Long [] businessIds){
        log.info("批量捞取");

        return tbBusinessService.scoopBatch(businessIds);
    }


}
